package com.moyq5.mvc.maker.test.bean.entity;

import java.math.BigDecimal;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.PrePersist;
import javax.persistence.Table;

import org.hibernate.annotations.DynamicUpdate;
import org.hibernate.annotations.GenericGenerator;

import com.moyq5.mvc.maker.test.bean.enums.ChannelQrcodeMode;
import com.moyq5.mvc.maker.test.bean.enums.ChannelQrcodeStatus;

/**
 * 个人/企业收款码信息，作为内部收款渠道资源
 * @author Moyq5
 * @date 2018年9月6日
 */
@Entity
@Table(name = "tra_channel_qrcode")
@DynamicUpdate
public class TraChannelQrcode implements java.io.Serializable {

	private static final long serialVersionUID = 1L;
	/**
	 * 收款码ID
	 */
	@Id
    @GeneratedValue(strategy = GenerationType.AUTO, generator = "native")@GenericGenerator(name = "native", strategy = "native")
    @Column(name = "qrcode_id")
	private Long qrcodeId;
	/**
	 * 收款码账户
	 */
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "account_id", nullable = false)
	private TraChannelQrcodeAccount account;
	/**
	 * 收款模式
	 */
	@Enumerated(EnumType.ORDINAL)
	@Column(name = "mode", nullable = false, columnDefinition="int(1) not null default '0'")
	private ChannelQrcodeMode mode;
	/**
	 * 收款码，收款码内容，非收款码地址。
	 */
	@Column(name = "qrcode", nullable = false, length = 500)
	private String qrcode;
	/**
     * 收款金额，收款码设置的收款金额
     */
    @Column(name = "amount", precision = 10, scale = 2)
    private BigDecimal amount;
    /**
	 * 收款备注，收款码设置的收款说明信息
	 */
	@Column(name = "remark", length = 100)
	private String remark;
	/**
	 * 状态，收款码使用状态
	 */
    @Enumerated(EnumType.ORDINAL)
    @Column(name = "status", nullable = false, columnDefinition="int(1) not null default '0'")
	private ChannelQrcodeStatus status;
    /**
	 * 状态说明
	 */
	@Column(name = "status_descr", length = 100)
	private String statusDescr;
	/**
	 * 使用时间，最近一次被使用的时间点
	 */
	@Column(name = "use_time", nullable = false, columnDefinition = "datetime default '1970-01-01 00:00:00'")
	private Date useTime;
    /**
	 * 添加时间，收款码入库时间
	 */
	@Column(name = "add_time", nullable = false, columnDefinition="datetime")
	private Date addTime;
	
	@PrePersist
	public void prePersist() {
		if (null == status) {
			status = ChannelQrcodeStatus.NORMAL;
		}
		if (null == statusDescr) {
			statusDescr = status.getText();
		}
		if (null == useTime) {
			useTime = new Date();
		}
		if (null == addTime) {
			addTime = new Date();
		}
	}

	public Long getQrcodeId() {
		return qrcodeId;
	}

	public void setQrcodeId(Long qrcodeId) {
		this.qrcodeId = qrcodeId;
	}

	public TraChannelQrcodeAccount getAccount() {
		return account;
	}

	public void setAccount(TraChannelQrcodeAccount account) {
		this.account = account;
	}

	public String getQrcode() {
		return qrcode;
	}

	public void setQrcode(String qrcode) {
		this.qrcode = qrcode;
	}

	public BigDecimal getAmount() {
		return amount;
	}

	public void setAmount(BigDecimal amount) {
		this.amount = amount;
	}

	public String getRemark() {
		return remark;
	}

	public void setRemark(String remark) {
		this.remark = remark;
	}

	public ChannelQrcodeStatus getStatus() {
		return status;
	}

	public void setStatus(ChannelQrcodeStatus status) {
		this.status = status;
	}

	public String getStatusDescr() {
		return statusDescr;
	}

	public void setStatusDescr(String statusDescr) {
		this.statusDescr = statusDescr;
	}

	public Date getUseTime() {
		return useTime;
	}

	public void setUseTime(Date useTime) {
		this.useTime = useTime;
	}

	public Date getAddTime() {
		return addTime;
	}

	public void setAddTime(Date addTime) {
		this.addTime = addTime;
	}

	public ChannelQrcodeMode getMode() {
		return mode;
	}

	public void setMode(ChannelQrcodeMode mode) {
		this.mode = mode;
	}

}
